package com.mygame.components

import com.almasb.fxgl.dsl.getGameWorld
import com.mygame.Const
import com.mygame.EType


class NearEntityComponent : TimerComponent() {
    override fun update() {
        try {
            if (!entity.isActive) return
            if (entity.properties.exists(Const.TAG_ENTITY)) {
                return
            }
            val tagEntity = getGameWorld().getEntityByID(EType.PLAYER.name, 1).get()
            if (entity.distanceBBox(tagEntity) < 200) {
                entity.properties.setValue(Const.TAG_ENTITY, tagEntity)
                entity.addComponent(CustomAIComponent())
                entity.addComponent(AttackComponent())
                println("开始追踪2222 ${entity.properties.getString(Const.NAME)}")
            }
        } catch (e: Exception) {
            //e.printStackTrace()
        }
        //println("${nearEntityList.size}个敌人$nearEntityList")
    }

}
